home *** CD-ROM | disk | FTP | other *** search
- /* ----------------------------------------------------------------- */
- /* TSpool Version 1.0 (C) Fourth Level Developments 1994 */
- /* ----------------------------------------------------------------- */
-
-
- /*
-
- TSpool is written by T.Southwell and is (C) Fourth Level Developements
- 1994. You may freely distribute these programs and documentation as long
- as you do not make a charge of any more than a reasonable copying fee. If
- you wish to revise or update the software then please do but you must then
- send a copy of the new version and source code to Fourth Level Developments.
- Fourth Level Developments will be willing to have this software incorporated in other software packages but
- in other programmes but you must first put your suggestions to us and obtain
- written permission before you start work on it.
-
-
- This is the main print spooler, its a standard AmigaDos filesystem handler
- which supports only the basic (Write/FindOutput/End) Packets. It saves
- the data to spool files in spool: and updates the list in t:
-
- Email: dev@flevel.demon.co.uk
-
- */
-
- #include <stdio.h>
-
- #ifndef EXEC_EXECBASE_H
- #include <exec/execbase.h>
- #endif
-
- #ifndef EXEC_ALERTS_H
- #include <exec/alerts.h>
- #endif
-
- #ifndef RESOURCES_MISC_H
- #include <resources/misc.h>
- #endif
-
- #ifndef HARDWARE_CIA_H
- #include <hardware/cia.h>
- #endif
-
- #ifndef DOS_FILEHANDLER_H
- #include <dos/filehandler.h>
- #endif
-
- #ifndef CLIB_EXEC_PROTOS_H
- #include <clib/exec_protos.h>
- #endif
-
- #ifndef CLIB_DOS_PROTOS_H
- #include <clib/dos_protos.h>
- #endif
-
- #ifndef CLIB_MISC_PROTOS_H
- #include <clib/misc_protos.h>
- #endif
-
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/dos_pragmas.h>
- #include <pragmas/misc_pragmas.h>
-
- /***********************************************/
- void __saveds FastPAR(void)
-
- {
- struct ExecBase *SysBase;
- struct DosLibrary *DOSBase;
- struct DosPacket *Packet;
- struct DeviceNode *DeviceNode;
- struct Process *MyProcess;
- long filecnt=0;
- BPTR filehan=0;
- BPTR listhan=0;
- long filesize=0;
- char filename[20];
- int startedt=0;
-
- SysBase=(struct ExecBase *)*(ULONG *)4;
- if (!(DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37L)))
- {
- Alert(AT_DeadEnd | AG_OpenLib | AO_DOSLib);
- }
- MyProcess=(struct Process *)(SysBase->ThisTask);
-
- Packet=WaitPkt();
- DeviceNode=BADDR(Packet->dp_Arg3);
- DeviceNode->dn_Task=&MyProcess->pr_MsgPort;
- ReplyPkt(Packet,DOSTRUE,0L);
-
- while (TRUE)
- {
- Packet=WaitPkt();
- switch(Packet->dp_Type)
- {
- case ACTION_FINDINPUT:
- case ACTION_FINDOUTPUT:
- case ACTION_FINDUPDATE:
-
- if (filehan)
- {
- ReplyPkt(Packet,DOSFALSE,0L);
- break;
- }
-
- if (startedt==0)
- {
- Execute("run spoolit",0L,0L);
- startedt=1;
- }
-
-
- filecnt++;
- sprintf(filename,"spool:spool%ld",filecnt);
- filesize=0;
- filehan=(BPTR)Open(filename,MODE_NEWFILE);
- if (filehan)
- ReplyPkt(Packet,DOSTRUE,0L);
- else
- ReplyPkt(Packet,DOSFALSE,0L);
- break;
-
- case ACTION_WRITE:
- {
- char *CharPointer;
-
- CharPointer=(char *)Packet->dp_Arg2;
- if (filehan)
- Write(filehan,CharPointer,(long)Packet->dp_Arg3);
- filesize+=Packet->dp_Arg3;
-
- if (filesize>=1024L*128L)
- {
- Close(filehan);
-
- while (listhan==0)
- listhan=(BPTR)Open("t:tspool-list",1004L);
- Seek(listhan,0L,OFFSET_END);
- Write(listhan,(char*)&filecnt,(long)4L);
- Close(listhan);
- listhan=0;
-
-
- filesize=0; filecnt++;
- sprintf(filename,"spool:spool%ld",filecnt);
- filehan=(BPTR)Open(filename,MODE_NEWFILE);
- }
- ReplyPkt(Packet,Packet->dp_Arg3,0L);
- }
- break;
-
- case ACTION_END:
-
- if (filehan)
- {
- Close(filehan);
-
- while (listhan==0)
- listhan=(BPTR)Open("t:tspool-list",1004L);
- Seek(listhan,0L,OFFSET_END);
- Write(listhan,(char*)&filecnt,(long)4L);
- Close(listhan);
- listhan=0;
-
-
- filehan=0; filesize=0;
- }
- ReplyPkt(Packet,DOSTRUE,0L);
- break;
-
- case ACTION_DIE:
- if (filehan)
- {
- Close(filehan);
-
- while (listhan==0)
- listhan=(BPTR)Open("t:tspool-list",1004L);
- Seek(listhan,0L,OFFSET_END);
- Write(listhan,(char*)&filecnt,(long)4L);
- Close(listhan);
- listhan=0;
-
-
- filehan=0; filesize=0;
- }
-
- if (IsMsgPortEmpty(&MyProcess->pr_MsgPort))
- {
- ReplyPkt(Packet,DOSTRUE,0L);
- UnLoadSeg(DeviceNode->dn_SegList);
- DeviceNode->dn_SegList=NULL;
- DeviceNode->dn_Task=NULL;
- CloseLibrary((struct Library *)DOSBase);
- return;
- }
- ReplyPkt(Packet,DOSFALSE,ERROR_OBJECT_IN_USE);
- break;
-
- default:
- ReplyPkt(Packet,DOSFALSE,ERROR_ACTION_NOT_KNOWN);
- break;
- }
- }
- }
-